import { defineStore } from 'pinia'

export const useTokenStore = defineStore('token', {
  state: () => ({
    token: null
  }),
  
  actions: {
    setToken(token) {
      this.token = token
      // 可选：将token保存到localStorage
      localStorage.setItem('token', token)
    },
    
    clearToken() {
      this.token = null
      localStorage.removeItem('token')
    },
    
    getToken() {
      return this.token || localStorage.getItem('token')
    }
  }
})